// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.

#pragma once

#include "CoreMinimal.h"
#include "Misc/Attribute.h"
#include "Layout/Visibility.h"
#include "Widgets/SWidget.h"
#include "IDetailCustomization.h"
#include "Input/Reply.h"

class IDetailChildrenBuilder;
class IPropertyHandle;
class ULODRecipe;

class FLODRecipeDetailsCustomization : public IDetailCustomization
{
public:
	static TSharedRef<IDetailCustomization> MakeInstance();

	// IDetailCustomization interface
	virtual void CustomizeDetails(IDetailLayoutBuilder& DetailLayout) override;
	// End of IDetailCustomization interface

protected:
	FLODRecipeDetailsCustomization();

	void GenerateStaticMeshesWidget(TSharedRef<IPropertyHandle> PropertyHandle, int32 ArrayIndex, IDetailChildrenBuilder& ChildrenBuilder, ULODRecipe* LODRecipe);
	void GenerateSkeletalMeshesWidget(TSharedRef<IPropertyHandle> PropertyHandle, int32 ArrayIndex, IDetailChildrenBuilder& ChildrenBuilder, ULODRecipe* LODRecipe);
	void GeneratePerLODPipelineWidget(TSharedRef<IPropertyHandle> PropertyHandle, int32 ArrayIndex, IDetailChildrenBuilder& ChildrenBuilder, ULODRecipe* LODRecipe);
	
	TSharedRef<SWidget> GenerateStreamedLODsWidget(FName PlatformGroupName, ULODRecipe* LODRecipe) const;
	bool AddStreamedLODsPlatform(FName PlatformGroupName, ULODRecipe* LODRecipe);
	bool RemoveStreamedLODsPlatform(FName PlatformGroupName, ULODRecipe* LODRecipe);
	TArray<FName> GetStreamedLODsPlatformOverrideNames(ULODRecipe* LODRecipe) const;
	int32 GetNumStreamedLODs(FName Platform, ULODRecipe* LODRecipe) const;
	void OnNumStreamedLODsChanged(int32 NewValue, FName Platform, ULODRecipe* LODRecipe);
	void OnNumStreamedLODsCommited(int32 InValue, ETextCommit::Type CommitInfo, FName Platform, ULODRecipe* LODRecipe);
	void SetNumStreamedLODsValue(int32 NewValue, FName Platform, ULODRecipe* LODRecipe);
	
	void GenerateMeshArrayItem(TSharedRef<IPropertyHandle> PropertyHandle, IDetailChildrenBuilder& ChildrenBuilder, TSharedRef<SWidget> RemoveButton);

	void OnRemoveStaticMesh(ULODRecipe* LODRecipe, const int32 MeshIndex);
	void OnRemoveSkeletalMesh(ULODRecipe* LODRecipe, const int32 MeshIndex);

	void UpdateLODSettingsVisibiility();
	EVisibility IsLODSettingsVisibile(const int32 LODIndex) const;

	void OnNumLODsChanged();

	FReply ApplyStreamedLODs(ULODRecipe* LODRecipe);

private:
	TArray<EVisibility> SettingsVisibility;
	TSharedPtr<IPropertyHandle> StaticMeshesHandle; 
	TSharedPtr<IPropertyHandle> SkeletalMeshesHandle;
	TSharedPtr<IPropertyHandle> PipelineSettingsHandle;
	TSharedPtr<IPropertyHandle> MiscSettingsHandle;
	TSharedPtr<IPropertyHandle> NumLODsHandle;
	TSharedPtr<IPropertyHandle> NumStreamedLODsHandle;

	class IDetailLayoutBuilder* Builder;
};
